package com.nikmesoft.android.referendumfriend.activities;

import java.util.ArrayList;

import com.nikmesoft.android.referendumfriend.adapters.activities_adapter;

import com.nikmesoft.android.referendumfriend.R;
import com.nikmesoft.android.referendumfriend.models.Activity_Group;
import com.nikmesoft.android.referendumfriend.models.item_activities;
import com.nikmesoft.android.referendumfriend.models.person;
import com.nikmesoft.android.referendumfriend.models.userhobies;
import com.nikmesoft.android.referendumfriend.service.LoginHandler;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class activity_post_hobby extends BaseActivity implements
		OnItemClickListener {
	private ListView myListView;
	String t = "Group: ";
	private activities_adapter adapter;
	TextView check;
	private TextView hoobycurrent;
	private int REQUEST_CODE = 100;
	private int REQUEST_CODE1 = 101;
	private int REQUEST_CODE2 = 102;
	Activity_Group user1;
	TextView postitem_activities;
	TextView nameGroup;
	ArrayList<item_activities> arrayitem_activities = new ArrayList<item_activities>();
	ArrayList<String> idactivity = new ArrayList<String>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_post_activities);
		Intent inten = this.getIntent();

		nameGroup = (TextView) findViewById(R.id.tvNameGroup);
		myListView = (ListView) findViewById(R.id.listview_activities);
		myListView.setDividerHeight(0);
		Intent intent = getIntent();
		Bundle bun = (Bundle) intent.getExtras();
		user1 = (Activity_Group) bun.getSerializable("user1");
		for (int i = 0; i < user1.getArr().size(); i++) {
			arrayitem_activities.add(new item_activities(user1.get(i)
					.getUsername_user(), user1.get(i).getContent(), user1
					.get(i).getAvatar_user(), user1.get(i).getLike(), user1
					.get(i).getDislike(),user1.get(i).getId_user(),user1.get(i).getIslike()));
			idactivity.add(user1.get(i).getId());
		}

		adapter = new activities_adapter(this, R.layout.item2,
				arrayitem_activities,idactivity);
		myListView.setAdapter(adapter);
		myListView.setOnItemClickListener(this);


	}

	public void callAdd(View v) {
		
		Intent intent = new Intent(this, Activity_addstt.class);
		startActivityForResult(intent, 106);

	}

	public void backhome(View v) {
		finish();
	}

	public void call_back(View v) {
		finish();
	}

	// public void myhobby(View v) {
	// Intent intent = new Intent(this, Group.class);
	// startActivityForResult(intent, REQUEST_CODE);
	// }

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub

		super.onActivityResult(requestCode, resultCode, data);

		if (requestCode == 106) {
			if (resultCode == RESULT_OK) {
				String name = data.getStringExtra("status").toString();
				arrayitem_activities
						.add(0, new item_activities(LoginHandler.result.getUsername(), name,LoginHandler.result.getAvatar(),"0","0",String.valueOf(LoginHandler.result.getId()),"false"));
				adapter.notifyDataSetChanged();
			}
		}
	}

	public void show(View v) {
		ImageView img=(ImageView)v;
		item_activities it=(item_activities)img.getTag();
		Intent intent = new Intent(this, show_profile.class);
		intent.putExtra("id",it.getId());
		startActivity(intent);
	}

	public void onItemClick(AdapterView<?> arg0, View view, int position,
			long arg3) {

		Intent intent = new Intent(this, detail_post.class);
		item_activities it = arrayitem_activities.get(position);
		intent.putExtra("status", it.getContent());
		intent.putExtra("nameuser", it.getUsername_user());
		startActivity(intent);

	}

}
